#!/bin/ash

touch /tmp/init.conf
touch /tmp/hosts
touch /tmp/ad
touch /tmp/dnsmasq.conf

touch /tmp/init.conf.tmp
touch /tmp/hosts.tmp
touch /tmp/ad.tmp
touch /tmp/dnsmasq.conf.tmp

until [ "`cat /tmp/init.conf.tmp | grep -c conf`" != 0 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ipv4init.conf -O /tmp/init.conf.tmp
done

until [ "`cat /tmp/dnsmasq.conf.tmp | grep -c start`" != 0 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ipv4dnsmasq.conf -O /tmp/dnsmasq.conf.tmp
done

until [ "`cat /tmp/hosts.tmp | grep -c start`" != 0 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ipv4hosts -O /tmp/hosts.tmp
done

until [ "`cat /tmp/ad.tmp | grep -c start`" != 0 ];do
sleep 5
wget http://routerdnsmasq.googlecode.com/git/ad -O /tmp/ad.tmp
done

mv /tmp/init.conf.tmp /tmp/init.conf
mv /tmp/dnsmasq.conf.tmp /tmp/dnsmasq.conf
mv /tmp/hosts.tmp /tmp/hosts
mv /tmp/ad.tmp /tmp/ad

chmod 644 /tmp/init.conf
chmod 644 /tmp/dnsmasq.conf
chmod 644 /tmp/hosts
chmod 644 /tmp/ad

killall dnsmasq
/etc/init.d/dnsmasq start